package openadmin.model.territory;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import openadmin.dao.Base;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

@Entity
@Table(name = "address", schema = "territory", uniqueConstraints = @UniqueConstraint(columnNames =  "description"))
public class Address implements Base, java.io.Serializable{
	
	/** attribute that contains the identifier*/
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)	
	private Integer id;

	/** attribute that contains the description (Ref catastral PIN), unique value*/
	@Length(max = 70)
	@NotNull
	private String description;
	
	/** attribute that contain the first number police*/		
	private Integer firstnumber;
	
	/** attribute that contain the first letter police*/		
	private char firstletter;
	
	/** attribute that contain the second number police*/		
	private Integer secondtnumber;
	
	/** attribute that contain the second letter police*/	
	private char secondletter;
	
	/** attribute that contain the kilometer*/	
	private Integer kilometer;
	
	/** attribute that contain an apartment block */	
	@Length(max = 4)
	private String block;
	
	/** attribute that contain the stairs */
	@Length(max = 2)
	private String stairs;
	
	/** attribute that contain the floor */
	@Length(max = 3)
	private String floor;
	
	/** attribute that contain the door */
	@Length(max = 3)
	private String door;
	
	/** Transient attribute that means that the system should make a log on any JPA operation of this class*/
	@Transient
	private boolean debuglog = true;
	
	/** Transient attribute that means that the system should make a historic on any JPA operation of this class*/
	@Transient
	boolean historiclog = false;
	
	/** attribute that contains the relationship with road*/
	@ManyToOne
	@JoinColumn(name = "street", nullable= false)
	private Street street;
	
	/** attribute that contains the relationship with road*/
	@ManyToOne
	@JoinColumn(name = "coordinate", nullable= false)
	private Coordinate coordinate;

	/**
	 * Constructor of the class Address.
	 * without parameters
	 */
	public Address() {
		
	}
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getDescription() {
		return description.toUpperCase();
	}

	public void setDescription() {
		this.description = street.getStreetName() + " " + firstnumber + " " + firstletter + " " +
							block + " " + stairs + " " + floor + " " + door + " " + kilometer;
	}

	public Integer getFirstnumber() {
		return firstnumber; 
	}

	public void setFirstnumber(Integer firstnumber) {
		this.firstnumber = firstnumber;
	}

	public char getFirstletter() {
		return firstletter;
	}

	public void setFirstletter(char firstletter) {
		this.firstletter = firstletter;
	}

	public Integer getSecondtnumber() {
		return secondtnumber;
	}

	public void setSecondtnumber(Integer secondtnumber) {
		this.secondtnumber = secondtnumber;
	}

	public char getSecondletter() {
		return secondletter;
	}

	public void setSecondletter(char secondletter) {
		this.secondletter = secondletter;
	}

	public Integer getKilometer() {
		return kilometer;
	}

	public void setKilometer(Integer kilometer) {
		this.kilometer = kilometer;
	}

	public String getBlock() {
		return block.toUpperCase();
	}

	public void setBlock(String block) {
		this.block = block;
	}

	public String getStairs() {
		return stairs.toUpperCase();
	}

	public void setStairs(String stairs) {
		this.stairs = stairs;
	}

	public String getFloor() {
		return floor.toUpperCase();
	}

	public void setFloor(String floor) {
		this.floor = floor;
	}

	public String getDoor() {
		return door.toUpperCase();
	}

	public void setDoor(String door) {
		this.door = door;
	}

	public boolean getDebugLog() {
		
		return debuglog;
	}

	public void setDebuglog(boolean debuglog) {
		this.debuglog = debuglog;
	}

	public Street getRoad() {
		return street;
	}

	public void setRoad(Street road) {
		this.street = road;
	}

	public Coordinate getCoodinate() {
		return coordinate;
	}

	public void setCoodinate(Coordinate coodinate) {
		this.coordinate = coodinate;
	}
	
	public boolean getHistoricLog() {
		return historiclog;
	}

	public void setHistoricLog(boolean historiclog) {
		this.historiclog = historiclog;
	}

	@Override
	public String toString(){
		 
		 return description;
	}
}
